<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link href="assets/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="css/style.css"/>
    <link href="assets/css/codemirror.css" rel="stylesheet">
    <link rel="stylesheet" href="assets/css/ace.min.css" />
    <link rel="stylesheet" href="font/css/font-awesome.min.css" />
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
    <![endif]-->
    <script src="js/jquery-1.9.1.min.js"></script>
    <script src="assets/js/typeahead-bs2.min.js"></script>
    <script src="js/lrtk.js" type="text/javascript" ></script>
    <script src="assets/js/jquery.dataTables.min.js"></script>
    <script src="assets/js/jquery.dataTables.bootstrap.js"></script>
    <script src="assets/layer/layer.js" type="text/javascript" ></script>
    <title>分类管理</title>
</head>

<body>
<div class="page-content clearfix">
    <div class="sort_style">
        <div class="border clearfix">
       <span class="l_f">
        <a href="javascript:ovid()" id="sort_add" class="btn btn-warning"><i class="fa fa-plus"></i> 添加评估类目</a>
        <a onclick="doSubmit()" class="btn btn-danger"><i class="fa fa-trash"></i> 批量删除</a>
           <script type="text/javascript">
               function doSubmit(){
                   layer.confirm('确认要删除吗？',{icon:0,},function(index){
                       var count = 0;
                       $('table tr > td:first-child input:checkbox').each(function (){
                           if(this.checked){
                               count++;
                           }
                       });
                       if(count > 0){
                           document.forms[0].submit()
                       }else {
                           layer.msg('请选择要删除评估类类目',{icon:1,time:1000});
                       }
                   });
               }
           </script>
       </span>
            <span class="r_f">${tips}</span>
        </div>
        <div class="sort_list">
            <form action="BasicInfoDeleteMultiServlet" method="post">
                <table class="table table-striped table-bordered table-hover" id="sample-table">
                    <thead>
                    <tr>
                        <th width="25px"><label><input type="checkbox" class="ace"><span class="lbl"></span></label></th>
                        <th width="100px">类目ID</th>
                        <th width="250px">类目名称</th>
                        <th width="100px">状态</th>
                        <th width="250px">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${basicInfo}" var="basicInfo">
                        <tr>
                            <td><label><input type="checkbox" class="ace" value="${basicInfo.basicInfoId}" name="basicInfoIds"><span class="lbl"></span></label></td>
                            <td>1</td>
                            <td>${basicInfo.basicInfoName}</td>
                            <c:choose>
                                <c:when test="${basicInfo.basicInfoStatus == 1}">
                                    <td class="td-status"><span class="label label-success radius">显示</span></td>
                                </c:when>
                                <c:otherwise>
                                    <td class="td-status"><span class="label label-defaunt radius">隐藏</span></td>
                                </c:otherwise>
                            </c:choose>

                            <td class="td-manage">
                                <c:choose>
                                <c:when test="${basicInfo.basicInfoStatus == 1}">
                                    <a onclick="member_stop(this,'${basicInfo.basicInfoId}')"  href="javascript:;" title="停用"  class="btn btn-xs btn-success"><i class="fa fa-check  bigger-120"></i></a>
                                </c:when>
                                <c:otherwise>
                                    <a onclick="member_start(this,'${basicInfo.basicInfoId}')"  href="javascript:;" title="启用"  class="btn btn-xs btn-defaunt"><i class="fa fa-check  bigger-120"></i></a>
                                </c:otherwise>
                            </c:choose>
                                <a title="编辑" href="BasicQueryServlet?basicInfoId=${basicInfo.basicInfoId}"  class="btn btn-xs btn-info" ><i class="fa fa-edit bigger-120"></i></a>
                                <a title="删除" href="javascript:;"  onclick="member_del(this,'${basicInfo.basicInfoId}')" class="btn btn-xs btn-warning" ><i class="fa fa-trash  bigger-120"></i></a>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
            </form>
        </div>
    </div>
</div>
<!--添加分类-->
<div class="sort_style_add margin" id="sort_style_add" style="display:none">
    <div class="">
        <form action="BasicInfoAddServlet" method="post" id="form1">
            <ul>
                <li>
                    <label class="label_name">类目名称</label>
                    <div class="col-sm-9">
                        <input name="basicInfoName" type="text" id="basicInfoName" placeholder="请输入要添加的类目" class="col-xs-10 col-sm-5" style="width: 500px;">
                    </div>
                </li>
            </ul>
        </form>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    $("#sample-table").DataTable({

    })
</script>
<script type="text/javascript">
    $('#sort_add').on('click', function(){
        layer.open({
            type: 1,
            title: '添加评估类名',
            maxmin: true,
            shadeClose: false, //点击遮罩关闭层
            area : ['750px' , ''],
            content:$('#sort_style_add'),
            btn:['提交','取消'],
            yes:function(index,layero){
                //检查类目名称是否输入
                if($("#basicInfoName").val() == ""){
                    layer.msg('请输入类目!',{icon:5,time:2000});
                }else {
                    $("#form1").submit();
                }
            }
        });
    })


    function checkLength(which) {
        var maxChars = 200; //
        if(which.value.length > maxChars){
            layer.open({
                icon:2,
                title:'提示框',
                content:'您出入的字数超多限制!',
            });
            // 超过限制的字数了就将 文本框中的内容按规定的字数 截取
            which.value = which.value.substring(0,maxChars);
            return false;
        }else{
            var curr = maxChars - which.value.length; //250 减去 当前输入的
            document.getElementById("sy").innerHTML = curr.toString();
            return true;
        }
    };
    /*广告图片-停用*/
    function member_stop(obj,id){
        layer.confirm('确认要隐藏吗？',function(index){
            $.post("BasicInfoStatusChangeServlet",{basicInfoId:id,oper:"stop"},function (data){
                // alert(data.code)
                if(data.code == 1000){
                    $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs " onClick="member_start(this,\''+id+'\')" href="javascript:;" title="显示"><i class="fa fa-close bigger-120"></i></a>');
                    $(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已隐藏</span>');
                    $(obj).remove();
                    layer.msg('关闭!',{icon: 5,time:1000});
                }else if(data.code == 1001){
                    layer.msg('隐藏操作失败!',{icon: 5,time:1000});
                }
            },"json")

        });
    }
    /*广告图片-启用*/
    function member_start(obj,id){
        layer.confirm('确认要显示吗？',{icon:0,},function(index){
            $.post("BasicInfoStatusChangeServlet",{basicInfoId:id,oper:"start"},function (data){
                // alert(data.code)
                if(data.code == 1000){
                    $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs btn-success" onClick="member_stop(this,\''+id+'\')" href="javascript:;" title="关闭"><i class="fa fa-check  bigger-120"></i></a>');
                    $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">显示</span>');
                    $(obj).remove();
                    layer.msg('显示!',{icon: 6,time:1000});
                }else if(data.code == 1001){
                    layer.msg('显示操作失败!',{icon: 5,time:1000});
                }
            },"json")

        });
    }
    /*广告图片-删除*/
    function member_del(obj,id){
        layer.confirm('确认要删除吗？',{icon:0,},function(index){
            $.post("BasicInfoDeleteServlet",{basicInfoId:id},function (data){
                if(data.code == 1000){
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!',{icon:1,time:1000});
                }else if(data.code == 1001){
                    layer.msg('删除操作失败!',{icon:1,time:1000});
                }
            },"json")

        });
    }
    //面包屑返回值
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.iframeAuto(index);
    $('.Order_form ,.ads_link').on('click', function(){
        var cname = $(this).attr("title");
        var cnames = parent.$('.Current_page').html();
        var herf = parent.$("#iframe").attr("src");
        parent.$('#parentIframe span').html(cname);
        parent.$('#parentIframe').css("display","inline-block");
        parent.$('.Current_page').attr("name",herf).css({"color":"#4c8fbd","cursor":"pointer"});
        //parent.$('.Current_page').html("<a href='javascript:void(0)' name="+herf+">" + cnames + "</a>");
        parent.layer.close(index);

    });
    function AdlistOrders(id){
        window.location.href = "Ads_list.html?="+id;
    };
</script>
<script type="text/javascript">
    // jQuery(function($) {
    //     var oTable1 = $('#sample-table').dataTable( {
    //         "aaSorting": [[ 1, "desc" ]],//默认第几个排序
    //         "bStateSave": true,//状态保存
    //         "aoColumnDefs": [
    //             //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
    //             {"orderable":false,"aTargets":[0,2,4,6,7,]}// 制定列不参与排序
    //         ] } );
        $('table th input:checkbox').on('click' , function(){
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function(){
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });

        });
        $('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});
        function tooltip_placement(context, source) {
            var $source = $(source);
            var $parent = $source.closest('table')
            var off1 = $parent.offset();
            var w1 = $parent.width();

            var off2 = $source.offset();
            var w2 = $source.width();

            if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) return 'right';
            return 'left';
        }

</script>